# 将学生的成绩, 从高到低排好序写到文件中

from main import get_scores
import matplotlib.pyplot as plt

# 冒泡排序
def bubble_sort(array, is_asc=True):
    i = 0
    while i < len(array):
        j = 0
        while j < len(array) - i - 1:
            if is_asc:
                if array[j][1] > array[j + 1][1]:
                    array[j], array[j + 1] = array[j + 1], array[j]
            else:
                if array[j][1] < array[j + 1][1]:
                    array[j], array[j + 1] = array[j + 1], array[j]
            j += 1
        i += 1
    return array


if __name__ == '__main__':
    score_map = get_scores()
    scores = list(score_map.items())
    bubble_sort(scores)
    print(scores)
    new_array = [item[1] for item in scores]
    x = range(len(new_array))
    plt.bar(x, new_array)
    plt.xlabel('Index')
    plt.ylabel('Value')
    plt.title('Array Visualization')

    plt.figure()
    plt.hist(new_array)
    plt.show()


